
<template>
  <div class="mainContainer">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item :key="index" v-for="(item,index) in list.slice(0, 3)" @click.native="liveDetails(item)">
        <img :src="item.fakuImg" alt="">
        <p class="text-1 name">{{item.title}}</p>
      </van-swipe-item>
    </van-swipe>

    <div class="hotNewList">
      <div class="title clearfix">
        <p class="fl">全部内容</p>
      </div>
      <div class="item-box">
        <van-list v-model="loading" :finished="finished" finished-text="暂无更多数据" @load="onLoad">
          <div class="item clearfix" v-for="item in list " :key="item.id" @click="details(item)">
            <div class="left">
              <img :src="item.fakuImg" alt="">
            </div>
            <div class="right">
              <div class="content">
                <p class="name">{{ item.title}}</p>
                <span class="time">{{ item.updateTime}}</span>
              </div>

            </div>
          </div>
        </van-list>
      </div>

    </div>
  </div>
</template>
<script>
import path from '@/network'
import API from '@/api.js'
export default {
  name: 'App',
  data () {
    return {
      total: 0,
      pagesize: 10,
      currentPage: 1,
      loading: false,
      finished: false,
      id: this.$route.query.firstId,
      list: [],
      activeId: '',
      dataTotal: ''
    }
  },
  created () {
  },
  mounted () {
    this.getSecondType(this.$route.query.firstId)
  },
  methods: {
    details: function (item) {
      this.$router.push({ name: 'details', query: { secondId: item.id, type: 1, title:'详情'} })
    },


    //获取list
    getSecondType (id) {
      path.getSecondType(
        id
      ).then(res => {
        if (res.success === 0) {
          this.activeId = res.rows[0].id;
          this.getLiveList(this.activeId)
        }
      })
    },


    //获取list
    getLiveList (id) {
      path.getLiveList(
        this.currentPage,
        this.pagesize,
        id
      ).then(res => {
        if (res.success === 0) {
          //this.dataTotal = res.total / this.pagesize == 0 ? res.total / this.pagesize : Math.ceil(res.total / this.pagesize);
          this.dataTotal = res.total
          if (this.dataTotal <= this.pagesize) {
            this.list = res.rows
          } else {
            this.currentPage++
            let arr = res.rows
            this.list = this.list.concat(arr)
          }

          this.loading = false
          if (this.list.length >= this.dataTotal) {
            this.finished = true //结束 
          }

        }
      })
    },


    onLoad () {
      if (this.activeId) {
        this.getLiveList(this.activeId)
      }

    },



  }
}
</script>